<template>
  <div class="box">
    <h2>子组件 add</h2>
    从vuex中获取的值:<label>{{$store.state.count}}</label>
    <br />
    <button @click="add">值+1</button>
    <button @click="lateradd">延时值+1</button>
    <button @click="asyncChange(555)">延时一秒将数值改成555</button>
  </div>
</template>

<script>
import {mapActions} from 'vuex'
export default {
  name: 'AddItem',
  methods:{
  ...mapActions(['asyncChange']),

  add(){
    // 在此触发mutatuions中的函数（increamCount）
  this.$store.commit('increamCount')
},
lateradd(){
  this.$store.dispatch('asyncIncream')

},
// changeNum(){
//   this.$store.dispatch('asyncChange',555)

// },
  }
}
</script>

<style lang="css" scoped>
.box {
  border: 3px solid #ccc;
  width: 400px;
  padding: 10px;
  margin: 20px;
}
h2 {
  margin-top: 10px;
}
</style>